﻿using System.Collections.Generic;
using System.Web;
using Netkk.Common.Interfaces.Services;
using Netkk.Core;

namespace Netkk.Library.Services
{
    public class UploadService : IUploadService
    {
        private readonly Uploader uploader;
        private UploadService()
        {
            uploader = new Uploader
                           {
                               UploadPath = HttpContext.Current.Server.MapPath("~/App_Data/Files/Downloads"),
                               IsOverwrite = true,
                               IsLowerName = true,
                               IsEncryptName = false,
                           };

            uploader.AllowedExtensions.AddRange(new List<string>
                                                    {
                                                        ".ppt",
                                                        ".doc",
                                                        ".xls",
                                                        ".pptx",
                                                        ".docx",
                                                        ".xlsx",
                                                        ".zip",
                                                        ".pdf"
                                                    });
        }

        public static IUploadService Create()
        {
            return new UploadService();
        }

        public bool DoUpload(string inputFileName)
        {
            return uploader.DoUpload(inputFileName);
        }

        public List<string> AllowedExtensions
        {
            get { return uploader.AllowedExtensions; }
        }

        public UploadedFile UploadedFile
        {
            get { return uploader.UploadedFile; }
        }

        public UploadError UploadError
        {
            get { return uploader.UploadError; }
        }
    }
}
